import Cookies from 'js-cookie'

const AppOpenId = 'WeChartAppOpenId'

// 获取token
export function getWeChartAppOpenId() {
  // 此处与TokenKey相同，此写法解决初始化时Cookies中不存在TokenKey报错

  return Cookies.get('WeChartAppOpenId')
}

export function setWeChartAppOpenId(openId: string) {
  // 24*60*60*1000
  // expires = 86400000
  // 提取关键信息进行存储
  // const paramsMap: paramsMapType = {
  //   name,
  //   expires: Date.now() + parseInt(expires),
  //   accessToken
  // };
  // expires > 0
  //   ? Cookies.set(TokenKey, dataString, {
  //       expires: expires / 86400000
  //     })
  //   : Cookies.set(TokenKey, dataString);
  Cookies.set(AppOpenId, openId)
}

// 删除token
export function removeWeChartAppOpenId() {
  Cookies.remove(AppOpenId)
}
